package com.zt.bigdata.elasticsearch.rest;

import com.google.common.collect.Maps;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.Random;

/**
 * @ClassName BuildTestData
 * @Description
 * @Author zhangtonghy
 * @Date 2019-05-13 16:22
 * @Copyright: 版权所有 (C) zt zt.
 * @注意：本内容仅限于zt内部传阅，禁止外泄以及用于其他的商业目的
 **/
public class BuildTestData {
    private static final ZoneId ZONE_ID = ZoneId.of("Asia/Shanghai");
    private static final String[] brands = new String[]{"huawei","apple","nokia","xiaomi","sony"};
    private static final String[] codes = new String[]{"404","405","400","505","502","500","200","202","201"};

    public static void main(String[] args) throws Exception {
        Random random = new Random();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

        while (true) {
            LocalDateTime localDateTime = LocalDateTime.now();
            ZonedDateTime zdt  =localDateTime.atZone(ZONE_ID);

            Map<String, Object> map = Maps.newHashMap();
            map.put("price", random.nextInt(10));
            map.put("number", random.nextInt(6));
            map.put("brand", brands[random.nextInt(1000)%5]);
            map.put("5g", true);
            map.put("tags", new String[]{"a","b"});
            map.put("code", codes[random.nextInt(1000)%9]);
            map.put("timestamp",zdt.format(dateTimeFormatter));
//            map.put("timestampstring",zdt.format(dateTimeFormatter));
            map.put("timestampstring","本内容仅限于zt内部传阅，禁止外泄以及用于其他的商业目的");

            ESRestUtils.indexDoc("time_series", "doc", null, map);

            System.out.println(map);
//            Thread.sleep(60000);

        }
    }
}
